// 计算购物车总数量
const goodsMsg =localStorage.getItem("goodsMsg") ? JSON.parse(localStorage.getItem("goodsMsg")) : [];
let num =0;
console.log(goodsMsg)
goodsMsg.forEach((val)=>{
    if(val){
        num+=parseInt(val.num)
       
    }

})
console.log(num)



// 登录守卫
let login_mark = document.querySelector("#login_mark");
let register_mark = document.querySelector("#register_mark");
let span_mark = document.querySelector(".span-r");

function defend(){
    if (localStorage.getItem("isLogin")==="OK"){
        login_mark.innerHTML=`<a href="#">
        ${localStorage.getItem("username")}
        <i class="iconfont icon-ico_arrowdown"></i>
        </a>`;
        register_mark.innerHTML=`<a href="./index.html">
        退出
        <i></i>
        </a>`;
        register_mark.onclick=function(){
            localStorage.setItem("isLogin","")
        };
        span_mark.innerHTML=num
        span_mark.previousElementSibling.innerHTML=`<a href="./cart.html">购物车</a>`
    
    
        }else{login_mark.innerHTML=`<a href="./login.html">
            请登录
            <i class="iconfont icon-ico_arrowdown"></i>
            </a>`;
            register_mark.innerHTML=`<a href="./register.html">
            注册
            <i></i>
            </a>`;
            span_mark.innerHTML=0
            span_mark.previousElementSibling.innerHTML=`<a href="">购物车</a>`
        }
    


}
defend()